﻿using System;
using System.IO;
using System.Reflection;

using log4net;

namespace VSTalk.Logger
{
    public static class LoggerFactory
    {
        private const string CONFIG_FILE = @"log4net.config";

        public static ILog Create(Type type)
        {
            if (LogManager.GetCurrentLoggers().Length == 0)
            {
                var location = Assembly.GetExecutingAssembly().Location;
                var dir = Path.GetDirectoryName(location);
                var path = Path.Combine(dir, CONFIG_FILE);
                log4net.Config.XmlConfigurator.Configure(new FileInfo(path));
            }
            return LogManager.GetLogger(type);
        }

        public static ILog Create<T>()
        {
            return LogManager.GetLogger(typeof(T));
        }
    }
}
